package org.baicaix.chat.views;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.baicaix.chat.ChatConstants;
import org.baicaix.chat.ChatMainFacade;


/**
 * @author Rocky Jiang
 * blog:www.blogjava.net/kissjava
 * */
public class InternalFrame extends JInternalFrame {

    public InternalFrame(String title) {
        this.setTitle(title);

        jbInit();
    }
    private JTextArea log = null;
    private JButton sendBtn = null;
    private JTextField message = null;

    private void jbInit() {
        this.setLayout(new BorderLayout());
        log = new JTextArea();
        JScrollPane pan = new JScrollPane(log);
        pan.setBorder(BorderFactory.createTitledBorder("日志"));
        message = new JTextField();
        sendBtn = new JButton("Send");
        sendBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ChatMainFacade.getInstance().sendNotification(ChatConstants.SEND_TO_FRAME, message.getText(), title);
            }
        });
        JPanel bottom = new JPanel();
        bottom.setLayout(new BorderLayout());
        bottom.add(message, BorderLayout.CENTER);
        bottom.add(sendBtn, BorderLayout.EAST);

        this.add(pan, BorderLayout.CENTER);
        this.add(bottom, BorderLayout.SOUTH);

    }

    public JTextArea getLog() {
        return log;
    }
}
